﻿using ControlHelper.Attributes; 
using Newtonsoft.Json; 
using System;
using System.Collections.Generic;
using System.Windows.Media;
using ReadOnlyAttribute = ControlHelper.Attributes.ReadOnlyAttribute;

namespace Creator.Core.Base
{
    public class BaseObject
    {
       /// <summary>
       /// 
       /// </summary>
       /// <param name="auto">自动生成ID</param>
        public BaseObject(bool auto = false)
        {
            if (auto)
                Id = BitConverter.ToInt64(Guid.NewGuid().ToByteArray(), 0);
        }
        [ReadOnly]
        
        public long Id { get;  set; }
        [Hide]
        
        public bool Active { get; set; } = true;
        [ReadOnly]
        public string Name { get; set; } = "BaseObject";
        [Hide]
        
        public BaseObject Parent { get; set; } = null;

        [Hide]
        
        public List<BaseObject> Children { get; set; } = new List<BaseObject>();
        /// <summary>
        /// 所包含的所有行为
        /// </summary>
        [Hide] 
        
        public List<Behaviour> Behaviours { get; set; } = new List<Behaviour>();
        [ReadOnly]
        public double Width { get; set; }
        [ReadOnly]
        public double Height { get; set; }
        [ReadOnly]
        public double PosX { get; set; }
        [ReadOnly]
        public double PosY { get; set; }

        [JsonIgnore] 
        
        public object OtherData { get; set; }

        [Hide]
        [JsonIgnore]
        
        public string Position => $"X:{PosX:F2},Y:{PosY:F2}";

        [Hide]
        
        public bool EnableThumbHorizontal { get; set; } = true;
        [Hide]
        
        public bool EnableThumbVertical { get; set; } = true;
 

        /// <summary>
        /// 当数据发生改变时
        /// </summary>
        [JsonIgnore]  
        public Action<BaseObject> OnDataChangedCallback;
        private bool active = true;

        public void RemoveBehaviour(Behaviour behaviour)
        {
            if (Behaviours.Contains(behaviour))
                Behaviours.Remove(behaviour);
        }
        public void AddBehaviour(Behaviour behaviour)
        {
            if (!Behaviours.Contains(behaviour))
                 Behaviours.Add(behaviour);
        }
        public override string ToString()
        {
            return $"{base.ToString()}_{Id}_{Name}";
        }
    }
}
